/*
 * TCSS 360 - Autumn 2011
 * Group2: ManuscriptPR 
 * 
 * UserCollectionTest2 class
 * Author: Tony Butterfield
 */
package user.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import user.Conference;
import user.Role;
import user.User;
import user.UserCollection;

/**
 * tests for loading the test data.
 * @author Tony Butterfield
 * @version 11/29/2011
 */
public class UserCollectionTest2
{
  /** test object. */
  private UserCollection my_users;
  
  /** test - first in the list. */
  private User my_user1;
  
  /** test user - last in the list. */
  @SuppressWarnings("unused")
  private User my_user2;
  
  /** harry's name. */
  private String my_name1 = "Answer, Harry";
  
  /** john's name. */
  private String my_name2 = "Connor, John";
  
  /** conference name. */
  private String my_conf_name = "Code Generation 2012";

  
  /**
   * set up test harness before each test.
   */
  @Before
  public void setUp() //throws IOException
  {
    my_users = new UserCollection();
    try
    {
      my_users.loadAllTestData();
    }
    catch (final IOException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    my_user1 = my_users.getUser(my_name1);
    my_user2 = my_users.getUser(my_name2);
  }

  /**
   * Test method for {@link user.UserCollection#loadAllTestData()}.
   * (testing to see if users were populated properly)
   * @throws IOException 
   */
  @Test
  public final void testLoadAllTestData() throws IOException
  {
    final List<String> test_list = my_users.getAllUserNames();
    
    assertEquals("User's last name is not Answer", "Answer", 
                 my_user1.getLastName());
    assertTrue("Harry Answer is not in the User Collection", 
               test_list.contains(my_name1));
    assertTrue("John Connor is not in the User Collection", 
               test_list.contains(my_name2));
    assertFalse("Gundam ZetaZeta does show in the list", 
                test_list.contains("ZetzZeta, Gundam"));    
  }
  
  /**
   * test method for {@link user.UserCollection#loadAllTestData()}.
   * (testing to see if users have conferences in their lists.)
   */
  @Test
  public final void testLoadAllTestData2() //throws IOException
  {
    
    final Conference conf1 = my_users.getUser(my_name1).getConference(my_conf_name);
    assertNotNull("Harry Answer is shown attending 'Code Generation 2012'", conf1);
    
    //System.out.println(role1.toString());
     
    assertFalse("No user is a member of any Conference", 
                my_users.getAllConferenceNames().isEmpty());
    assertFalse("Harry Answer is not a member of any Conference", 
                my_user1.getAllConferenceNames().isEmpty());
    assertTrue("Harry Answer is not a member of Code Generation 2012", 
               my_user1.getAllConferenceNames().contains(my_conf_name));
    assertEquals("Harry Answer is not a Program Chair", Role.PROGRAM_CHAIR, 
                 my_user1.getRole(my_conf_name));
    assertEquals("BAAAAAD", Role.REVIEWER, 
                 my_users.getUser("Butterfield, Tony").getRole("Visual Studio Live! Orlando 2011"));
    assertEquals("BAAAAAAAAAAAAAD.", Role.AUTHOR, 
                 my_users.getUser("Galt, John").getRole(my_conf_name));
  }
  
}
